package com.benny.openlauncher.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class AppBackgroundView extends LinearLayout {


    public static final class BackgroundLayoutParams extends LinearLayout.LayoutParams {
        private int _x;
        private int _xSpan = 1;
        private int _y;
        private int _ySpan = 1;

        public final int getX() {
            return _x;
        }

        public final void setX(int v) {
            _x = v;
        }

        public final int getY() {
            return _y;
        }

        public final void setY(int v) {
            _y = v;
        }

        public final int getXSpan() {
            return _xSpan;
        }

        public final void setXSpan(int v) {
            _xSpan = v;
        }

        public final int getYSpan() {
            return _ySpan;
        }

        public final void setYSpan(int v) {
            _ySpan = v;
        }

        public BackgroundLayoutParams(int w, int h, int x, int y) {
            super(w, h);
            _x = x;
            _y = y;
        }

        public BackgroundLayoutParams(int w, int h, int x, int y, int xSpan, int ySpan) {
            super(w, h);
            _x = x;
            _y = y;
            _xSpan = xSpan;
            _ySpan = ySpan;
        }

        public BackgroundLayoutParams(int w, int h) {
            super(w, h);
        }
    }

    View view;

    public CellContainer.LayoutParams getLayoutParams2() {
        return (CellContainer.LayoutParams) view.getLayoutParams();
    }

    public AppBackgroundView(Context context, View view, CellContainer.LayoutParams layoutParams) {
        super(context);
        Log.d("CellContainer", "class :" + view.getClass().getName() +
                "-layoutParams: " + view.getLayoutParams().getClass().getName());
        this.view = view;
        setGravity(Gravity.CENTER);
        view.setLayoutParams(new BackgroundLayoutParams(
                layoutParams.width, layoutParams.height, layoutParams.getX(),
                layoutParams.getY(), layoutParams.getXSpan(), layoutParams.getYSpan()));
        addView(view);
        setBackgroundColor(0x66666666);
    }

    public AppBackgroundView(Context context) {
        super(context);
    }

    public AppBackgroundView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public AppBackgroundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

}
